 ALTER PROC sp_insert_ct_gp_vendor_mappings_with_accounts ( @ctVendorId INT, @gpVendorId INT, @vendorNumber VARCHAR(15), @payMentTerms VARCHAR(50), @chequeBookId VARCHAR(50), @purchaseAccountId VARCHAR(50), @vendorAccountNumber Varchar(50), @defaultAccountNumber Varchar(50) ) 
 AS
 BEGIN
 DECLARE @tempVendorId INT
 
 	IF @ctVendorId <> -1
 	BEGIN
 		SELECT @tempVendorId = CT_Vendor_Id FROM CT_GP_Vendor_Mapping WHERE CT_Vendor_Id = @ctVendorId
 		
 		IF @tempVendorId IS NULL
 		BEGIN
 			--INSERT INTO CT_GP_Vendor_Mapping VALUES ( @ctVendorId, @gpVendorId )
			INSERT INTO CT_GP_Vendor_Mapping( [CT_Vendor_Id], [GP_Vendor_Id], [GP_Vendor_Number], [Payment_Terms], [CheckBookId], [PurchaseAccountId], [VendorAccountNumber], [DefaultAccountNumber])
			VALUES( @ctVendorId, @gpVendorId, @vendorNumber, @payMentTerms, @chequeBookId, @purchaseAccountId, @vendorAccountNumber, @defaultAccountNumber )
 		END
 		ELSE
 		BEGIN
 			UPDATE CT_GP_Vendor_Mapping SET GP_Vendor_Id = @gpVendorId, Payment_Terms = @payMentTerms, CheckBookId = @chequeBookId, PurchaseAccountId = @purchaseAccountId, VendorAccountNumber = @vendorAccountNumber, DefaultAccountNumber = @defaultAccountNumber  WHERE CT_Vendor_Id = @ctVendorId
 		END
 	END	
END


